package org.blog.controller;

import org.blog.entity.Article;
import org.blog.entity.vo.NewArticleVO;
import org.blog.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
public class IndexController {

    @Autowired
    private ArticleService articleService;


    @GetMapping("frontIndex")
    public ModelAndView frontIndex() {
        ModelAndView modelAndView = new ModelAndView("front/index");

        // 返回热点文章 ,默认10篇
        List<Article> hotArticles = articleService.getHotArticles(10);

        // 返回最新文章 ，5篇
        List<NewArticleVO> newArticles = articleService.getNewArticles(5);

        modelAndView.addObject("hotArticles", hotArticles);
        modelAndView.addObject("newArticles", newArticles);

        return modelAndView;
    }
}
